package com.hly.musicbackground.model.index.rest;

import com.hly.musicbackground.domain.SelectCondition;
import com.hly.musicbackground.model.index.params.SelectParams;
import com.hly.musicbackground.model.index.service.SelectConditionService;
import com.hly.musicbackground.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/select")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(tags = "筛选条件")
public class SelectConditionController {

    private final SelectConditionService selectConditionService;

    @GetMapping("/list")
    @ApiOperation(value = "获取筛选条件")
    public Result list(@RequestParam SelectParams params){
        return Result.ok(selectConditionService.getSelectList(params));
    }

    @PostMapping("/edit")
    @ApiOperation(value = "添加/修改添加")
    public Result edit(@RequestBody SelectCondition selectCondition){
        selectConditionService.edit(selectCondition);
        return Result.ok();
    }

    @PostMapping("/del")
    @ApiOperation(value = "删除")
    public Result del(@RequestParam int id){
        selectConditionService.removeById(id);
        return Result.ok();
    }
}
